package com.sunrise.xdoc.helper;

import ar.com.fdvs.dj.domain.Style;
import ar.com.fdvs.dj.domain.builders.ColumnBuilder;
import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
import ar.com.fdvs.dj.domain.constants.Border;
import ar.com.fdvs.dj.domain.constants.Font;
import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
import ar.com.fdvs.dj.domain.constants.VerticalAlign;
import ar.com.fdvs.dj.domain.customexpression.DJSimpleExpression;
import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;

/**
 * The Class ReportBuilder.
 *
 * @author Nguyen Duc Dung
 * @since 5/19/13 6:15 AM
 */
public class ReportHelper {

    public static final Font DEFAULT_FONT = new Font(8, "Arial", "/fonts/Arial.ttf",
            Font.PDF_ENCODING_Identity_H_Unicode_with_horizontal_writing, true);
    public static final Font TITLE_FONT = new Font(14, "Arial", "/fonts/Arial.ttf",
            Font.PDF_ENCODING_Identity_H_Unicode_with_horizontal_writing, true);
    public static final Font SUB_TITLE_FONT = new Font(13, "Arial", "/fonts/Arial.ttf",
            Font.PDF_ENCODING_Identity_H_Unicode_with_horizontal_writing, true);

    public static Style TITLE_STYLE = new Style();
    public static Style SUB_TITLE_STYLE = new Style();
    public static Style HEADER_STYLE = new Style();
    public static Style DETAIL_STYLE = new Style();
    public static Style NUMBER_STYLE = new Style();
    public static Style NAME_STYLE = new Style();

    static {
        TITLE_FONT.setBold(true);

        TITLE_STYLE.setFont(TITLE_FONT);
        TITLE_STYLE.setHorizontalAlign(HorizontalAlign.CENTER);
        TITLE_STYLE.setVerticalAlign(VerticalAlign.MIDDLE);

        SUB_TITLE_STYLE.setFont(SUB_TITLE_FONT);
        SUB_TITLE_STYLE.setHorizontalAlign(HorizontalAlign.CENTER);
        SUB_TITLE_STYLE.setVerticalAlign(VerticalAlign.MIDDLE);
        SUB_TITLE_STYLE.setPaddingBottom(10);

        HEADER_STYLE.setFont(DEFAULT_FONT);
        HEADER_STYLE.getFont().setBold(true);
        HEADER_STYLE.setBorder(Border.THIN());
        HEADER_STYLE.setHorizontalAlign(HorizontalAlign.CENTER);
        HEADER_STYLE.setVerticalAlign(VerticalAlign.MIDDLE);

        DETAIL_STYLE.setFont(DEFAULT_FONT);
        DETAIL_STYLE.setHorizontalAlign(HorizontalAlign.LEFT);
        DETAIL_STYLE.setVerticalAlign(VerticalAlign.MIDDLE);
        DETAIL_STYLE.setBorderLeft(Border.THIN());
        DETAIL_STYLE.setBorderRight(Border.THIN());
        DETAIL_STYLE.setBorderBottom(Border.THIN());

        NUMBER_STYLE.setFont(DEFAULT_FONT);
        NUMBER_STYLE.setHorizontalAlign(HorizontalAlign.LEFT);
        NUMBER_STYLE.setVerticalAlign(VerticalAlign.MIDDLE);
        NUMBER_STYLE.setBorderLeft(Border.THIN());
        NUMBER_STYLE.setBorderRight(Border.THIN());
        NUMBER_STYLE.setBorderBottom(Border.THIN());
        NUMBER_STYLE.setPaddingLeft(5);

        NAME_STYLE.setFont(DEFAULT_FONT);
        NAME_STYLE.setVerticalAlign(VerticalAlign.MIDDLE);
        NAME_STYLE.setHorizontalAlign(HorizontalAlign.LEFT);
        NAME_STYLE.setBorderLeft(Border.THIN());
        NAME_STYLE.setBorderRight(Border.THIN());
        NAME_STYLE.setBorderBottom(Border.THIN());
        NAME_STYLE.setPaddingLeft(5);
    }

    private ReportHelper() {

    }

    public static FastReportBuilder getReportBuilder() {
        FastReportBuilder builder = new FastReportBuilder();
        builder.setUseFullPageWidth(true);
        builder.setHeaderHeight(20);
        builder.setDefaultStyles(TITLE_STYLE, SUB_TITLE_STYLE, HEADER_STYLE, null);
        return builder;
    }

    public static AbstractColumn buildSttColumn() {
        AbstractColumn STT_COLUMN = ColumnBuilder.getNew()
                .setTitle("STT")
                .setCustomExpression(new DJSimpleExpression(DJSimpleExpression.TYPE_VARIABLE, "COLUMN_COUNT", Integer.class.getName()))
                .setStyle(DETAIL_STYLE)
                .setWidth(30)
                .setFixedWidth(true)
                .build();
        return STT_COLUMN;
    }

}
